package com.nomito.minimito.service.impl;

import com.nomito.minimito.vo.TopicCommentVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nomito.minimito.common.utils.PageUtils;
import com.nomito.minimito.common.utils.Query;

import com.nomito.minimito.dao.SqTopicCommentDao;
import com.nomito.minimito.entity.SqTopicCommentEntity;
import com.nomito.minimito.service.SqTopicCommentService;


@Service("sqTopicCommentService")
public class SqTopicCommentServiceImpl extends ServiceImpl<SqTopicCommentDao, SqTopicCommentEntity> implements SqTopicCommentService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SqTopicCommentEntity> page = this.page(
                new Query<SqTopicCommentEntity>().getPage(params),
                new QueryWrapper<SqTopicCommentEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SqTopicCommentEntity> getTopicCommentList(Long topicId) {
        List<SqTopicCommentEntity> sqTopicCommentEntities = new ArrayList<>();

        sqTopicCommentEntities=this.baseMapper.selectList(new QueryWrapper<SqTopicCommentEntity>()
                .eq("is_deleted",0)
                .eq("topic_id",topicId)
                .orderByDesc("gmt_create"));

        return sqTopicCommentEntities;
    }

    @Override
    public void insertTopicComment(TopicCommentVo topicCommentVo) {
        SqTopicCommentEntity sqTopicCommentEntity = new SqTopicCommentEntity();
        sqTopicCommentEntity.setCommentId(topicCommentVo.getCommentId());
        sqTopicCommentEntity.setTopicId(topicCommentVo.getTopicId());
        sqTopicCommentEntity.setTopiCommentText(topicCommentVo.getTopiCommentText());
        sqTopicCommentEntity.setStarCount(0L);
        this.baseMapper.insert(sqTopicCommentEntity);
    }

}